Skip to content

Fix/creative packet lores#246

Merged
twisti-dev merged 2 commits into
version/1.21.11from
fix/creative-packet-lores
Mar 14, 2026
Merged

Fix/creative packet lores#246
twisti-dev merged 2 commits into
version/1.21.11from
fix/creative-packet-lores

Conversation

@twisti-dev

Copy link
Copy Markdown
Contributor

This pull request refactors and improves the PacketLoreListener in the Bukkit server module, focusing on how item lore is handled in Minecraft packet events. The changes modernize the code, make lore handling more robust, and ensure original lore is preserved and restored correctly.

Lore handling improvements

  • Switched to using ConcurrentHashMap for loreHandlers and loreHandlersGlobal, improving thread safety and performance.
  • Introduced a new mechanism to store and restore the original item lore using a custom data key (ORIGINAL_LORE_KEY) and Minecraft's CustomData API, ensuring the original lore can be restored after modifications.
  • Refactored lore processing to always work with a mutable copy and removed the use of a prefix string for lore lines, simplifying the lore update logic.

Packet event handler updates

  • Changed several packet event listener methods to return modified packet instances with updated item stacks, rather than mutating items in place, improving clarity and functional style.

Code cleanup and modernization

  • Removed unused imports and legacy utility functions, and replaced them with more standard Java/Kotlin collections and concurrency utilities.
  • Updated the plugin version in gradle.properties to 1.21.11-2.63.1.

@twisti-dev twisti-dev self-assigned this Mar 14, 2026
Copilot AI review requested due to automatic review settings March 14, 2026 16:06
@twisti-dev twisti-dev merged commit fe7b763 into version/1.21.11 Mar 14, 2026
6 checks passed
@twisti-dev twisti-dev deleted the fix/creative-packet-lores branch March 14, 2026 16:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Bukkit server-side packet lore pipeline to modify outgoing item lore via handlers while preserving/restoring the original lore using DataComponents.CUSTOM_DATA instead of the previous prefix-based approach.

Changes:

  • Reworked clientbound packet listeners to return new packet instances with copied/updated ItemStacks.
  • Switched lore cleanup/restoration to snapshot original ItemLore into CUSTOM_DATA and restore it on ServerboundSetCreativeModeSlotPacket.
  • Replaced synchronized fastutil maps with ConcurrentHashMap-based handler registries.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/lore/PacketLoreListener.kt Replaces prefix-based lore tagging with CUSTOM_DATA snapshot/restore and returns updated packet copies for clientbound inventory packets.
gradle.properties Bumps project version from 1.21.11-2.63.0 to 1.21.11-2.63.1.

Comment on lines 95 to +105
val updatedNmsLore = ItemLore(
lore.asSequence()
mutableLore.asSequence()
.map { it.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE) }
.map { it.toNms() }
.map { lorePrefix.copy().append(it) }
.toList()
)

item.set(DataComponents.LORE, updatedNmsLore)
CustomData.update(DataComponents.CUSTOM_DATA, item) { tag ->
tag.store(ORIGINAL_LORE_KEY.asString(), ItemLore.CODEC, nmsLore)
}
Comment on lines 48 to +55
@ClientboundListener
fun onContainerData(event: ClientboundContainerSetSlotPacket) {
makeUpdatedItemStack(event.item)
fun onContainerData(event: ClientboundContainerSetSlotPacket): ClientboundContainerSetSlotPacket {
return ClientboundContainerSetSlotPacket(
event.containerId,
event.stateId,
event.slot,
makeUpdatedItemStack(event.item.copy())
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants